// pages/page/gooddetail/gooddetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autoplay: true,
    indicatorDots: false,
    bannerHeight: 800,

    bannerCurrentSelect: 1,
    bannerSize: 8,
    youhuijuan: "优惠券",

    readMore: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.getGoodDataFromService(options.sellerId, options.goodId);// 从服务器中获取商品数据
    // http://picture.teapaopao.com/cpp/dist/good.html?goodId=14610&sellerId=11143
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 从服务器中获取商品数据
   */
  getGoodDataFromService: function (sellerId, goodId) {
    var that = this;
    console.log("sellerId=" + sellerId);
    console.log("goodId=" + goodId);
    // http://120.55.137.143:54321/service/teabubble/shop_paopao_goods?methods=getH5ActivityInfo&jsonp=true&sellerId=11143&activityId=14610&jsonp_method=_jsonpevpeagxamru0nrzw2m24oswcdi
    wx.request({
      url: "http://120.55.137.143:54321/service/teabubble/shop_paopao_goods?methods=getH5ActivityInfo",
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        "sellerId": sellerId,
        "activityId": goodId,
      }, success: function (res) {
        console.log(res.data);
        var activityImgUrlArray = res.data.content.activityImgUrl.split(",");
        var packImgUrlArray = res.data.content.packImgUrl.split(",");
        res.data.content.activityImgUrlArray = activityImgUrlArray;
        res.data.content.packImgUrlArray = packImgUrlArray;
        var goodsParamArrayTemp = new Array();
        goodsParamArrayTemp = JSON.parse(res.data.content.goodsParams);


        res.data.content.goodsParamArray = goodsParamArrayTemp;
        that.setData({
          goodInfo: res.data.content,
          bannerSize: res.data.content.activityImgUrlArray.length,
        });
      }
    })
  },
  /**
   * banner滑动的监听
   */
  bannerChange: function (event) {
    this.setData({
      bannerCurrentSelect: event.detail.current + 1,

    });
  },
  /**
   * banner图片加载出来的监听
   */
  bannerLoad: function (event) {

    // if (event.target.dataset.position == 0) {
    // if (this.data.bannerHeight < event.detail.height) {
    // this.setData({
    // bannerHeight: event.detail.height,
    // });
    // }
  },
  /**
   * 阅读更多点击
   */
  readMoreClick: function (event) {
    this.setData({
      readMore:true,
    });
  }
})
 